package test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class C extends JFrame {
    /**
	 * 
	 */
	private static final long serialVersionUID = 2085358600808248717L;

	C() {
        final JTable jt = new JTable(new Object[][]{{5,1},{3,8},{9,4}}, new Object[]{'A','B'});
        jt.setAutoCreateRowSorter(true);

        add(new JScrollPane(jt));
        add(new JButton(new AbstractAction("显示选定行最左列的值") {
            /**
			 * 
			 */
			private static final long serialVersionUID = -7220823798990197401L;

			public void actionPerformed(ActionEvent ae) {
                int 转换成的模型行 = jt.convertRowIndexToModel(jt.getSelectedRow()),
                    转换成的模型列 = jt.convertColumnIndexToModel(0);
                JOptionPane.showMessageDialog(null,
                        "<HTML>" +
                        "用 JTable.getValueAt() 获取的值是 " +
                        jt.getValueAt(jt.getSelectedRow(), 0) +
                        "<P>" +
                        "用 JTable.getModel().getValueAt() 和转换过的行列号获取的值是 " +
                        jt.getModel().getValueAt(转换成的模型行, 转换成的模型列)+转换成的模型行+转换成的模型列);

            }
        }), BorderLayout.SOUTH);

        pack();
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args) { new C(); }
}
